<?php

if (!function_exists('isXmlHttpRequest')) {

	function isXmlHttpRequest() {
		return isset($_SERVER['x-requested-with']) && strtolower($_SERVER['x-requested-with']) == 'xmlhttprequest';
	}

}

if (!function_exists('requestGet')) {

	function requestGet($key, $default = false) {
		return isset($_GET[$key]) ? $_GET[$key] : $default;
	}

}

if (!function_exists('requestPost')) {

	function requestPost($key, $default = false) {
		return isset($_POST[$key]) ? $_POST[$key] : $default;
	}

}

if (!function_exists('setFlash')) {

	function setFlash($key, $value) {
		$_SESSION[$key] = $value;
	}

}

if (!function_exists('getFlash')) {

	function getFlash($key, $default = null) {
		if (isset($_SESSION[$key])) {
			$tmp = $_SESSION[$key];
			unset($_SESSION[$key]);
			return $tmp;
		}
		return $default;
	}

}

if (!function_exists('redirect')) {

	function redirect($url) {
		if (!preg_match('/^http\:\/\//', $url)) {
			$url = str_replace('//', '/', url($url));
		}
		header('Location:' . $url);
		exit(0);
	}

}

if (!function_exists('url')) {

	function url($url) {
		//return SITE_URL.(strpos($url,'.php')===false?'':'/?').$url;
		return SITE_URL . (preg_match('/\.(jpeg|jpg|png|gif|css|js)/i', $url) ? '' : '/?') . $url;
	}

}


if (!function_exists('lcfirst')) {

	function lcfirst($string) {
		$letter = $string{0};
		if (ord($letter) <= ord('Z') && ord($letter) >= ord('A')) {
			$diff = ord('a') - ord('A');
			return chr(ord($letter) + $diff) . substr($string, 1);
		}
		return $string;
	}

}

if (!function_exists('ucfirst')) {

	function ucfirst($string) {
		$letter = $string{0};
		if (ord($letter) <= ord('z') && ord($letter) >= ord('a')) {
			$diff = ord('a') - ord('A');
			return chr(ord($letter) - $diff) . substr($string, 1);
		}
		return $string;
	}

}

/* sqlite functions */
if (!function_exists('sqliteNow')) {

	function sqliteNow() {
		return time();
	}

}

function isWindows() {
	$unameSegments = explode(' ', php_uname());
	return strtoupper($unameSegments[0]) == 'WINDOWS';
}

function _2uc($string) {
	if (strpos($string, '_') !== false) {
		$segments = explode('_', $string);
		$result = '';
		foreach ($segments as $segment) {
			$result .= ucfirst($segment);
		}
		return $result;
	}

	return $string;
}

function imageResize($source, $height, $width) {

}